{"ast":null,"code":"var _jsxFileName = \"/data/messenger.client/src/containers/DialogInput.tsx\",\n  _s = $RefreshSig$();\nimport React from \"react\";\nimport { DialogInput as DialogInputComponent } from \"../components\";\nimport { Context } from \"../index\";\nimport { observer } from \"mobx-react-lite\";\nimport data from '@emoji-mart/data';\nimport { init, getEmojiDataFromNative } from 'emoji-mart';\nimport { jsxDEV as _jsxDEV } from \"react/jsx-dev-runtime\";\ninit({\n  data\n});\nconst DialogInput = _ref => {\n  _s();\n  let {\n    chat\n  } = _ref;\n  const {\n    store\n  } = React.useContext(Context);\n  const [value, setValue] = React.useState(false);\n  const [textField, setTextField] = React.useState('');\n  const [emojiPickerVisible, setEmojiPickerVisible] = React.useState(false);\n  const [flagForStyle, setFlagForStyle] = React.useState(false);\n  const [cursorPosition, setCursorPosition] = React.useState(0);\n  const pickerRef = React.useRef(null);\n  const textAreaRef = React.useRef(null);\n  const maxSizeMessage = 500;\n  const emojiRE = /(\\p{Emoji_Presentation}|\\p{Extended_Pictographic})/gu;\n  React.useEffect(() => {\n    var _textAreaRef$current;\n    (_textAreaRef$current = textAreaRef.current) === null || _textAreaRef$current === void 0 ? void 0 : _textAreaRef$current.focus();\n    if (textField.length > maxSizeMessage * 0.05) {\n      setFlagForStyle(true);\n    } else {\n      setFlagForStyle(false);\n    }\n    if (textField.length > 0) {\n      setValue(true);\n    } else {\n      setValue(false);\n    }\n  }, [textField]);\n  React.useEffect(() => {\n    if (emojiPickerVisible) {\n      const handleClick = e => {\n        var _pickerRef$current;\n        if (!pickerRef.current) return;\n        if (!((_pickerRef$current = pickerRef.current) !== null && _pickerRef$current !== void 0 && _pickerRef$current.contains(e.target))) {\n          var _textAreaRef$current2;\n          (_textAreaRef$current2 = textAreaRef.current) === null || _textAreaRef$current2 === void 0 ? void 0 : _textAreaRef$current2.focus();\n          setEmojiPickerVisible(false);\n        }\n      };\n      document.addEventListener('click', handleClick);\n      return () => {\n        document.removeEventListener('click', handleClick);\n      };\n    }\n  }, [emojiPickerVisible]);\n  React.useEffect(() => {\n    var _textAreaRef$current3;\n    if ((_textAreaRef$current3 = textAreaRef.current) !== null && _textAreaRef$current3 !== void 0 && _textAreaRef$current3.selectionEnd) {\n      textAreaRef.current.selectionEnd = cursorPosition;\n    }\n  }, [cursorPosition]);\n  React.useEffect(() => {\n    setTextField('');\n    setCursorPosition(0);\n  }, [chat]);\n  const toggleEmojiPicker = () => {\n    var _textAreaRef$current4;\n    (_textAreaRef$current4 = textAreaRef.current) === null || _textAreaRef$current4 === void 0 ? void 0 : _textAreaRef$current4.focus();\n    setEmojiPickerVisible(!emojiPickerVisible);\n  };\n  const addEmoji = identifier => {\n    const ref = textAreaRef.current;\n    ref === null || ref === void 0 ? void 0 : ref.focus();\n    const start = textField.substring(0, ref === null || ref === void 0 ? void 0 : ref.selectionStart);\n    const end = textField.substring((ref === null || ref === void 0 ? void 0 : ref.selectionStart) || 500);\n    setTextField(start + identifier + end);\n    setCursorPosition(start.length + identifier.length);\n  };\n  const uploadDocumentHandler = React.useCallback(e => {\n    let collectionFiles = [];\n    if (e.target.files) {\n      [...e.target.files].forEach(item => {\n        const file = item;\n        collectionFiles.push(file);\n      });\n    }\n    e.target.value = '';\n  }, [store]);\n  const handleSendMessage = e => {\n    if (textField.length - 1 <= maxSizeMessage) {\n      const resultTextValue = textField.replace(emojiRE, match => {\n        getEmojiDataFromNative(match).then(res => {\n          console.log(res.shortcodes);\n        });\n        return match;\n      });\n      console.log(resultTextValue);\n      setTextField('');\n    }\n  };\n  return /*#__PURE__*/_jsxDEV(DialogInputComponent, {\n    toggleEmojiPicker: toggleEmojiPicker,\n    emojiPickerVisible: emojiPickerVisible,\n    setEmojiPickerVisible: setEmojiPickerVisible,\n    value: value,\n    textField: textField,\n    setTextField: setTextField,\n    maxSizeMessage: maxSizeMessage,\n    uploadDocumentHandler: uploadDocumentHandler,\n    handleSendMessage: handleSendMessage,\n    pickerRef: pickerRef,\n    addEmoji: addEmoji,\n    flagForStyle: flagForStyle,\n    textAreaRef: textAreaRef\n  }, void 0, false, {\n    fileName: _jsxFileName,\n    lineNumber: 111,\n    columnNumber: 9\n  }, this);\n};\n_s(DialogInput, \"DGcOdYs8wSS2n45YUZIirfnfB5w=\");\n_c = DialogInput;\nexport default _c2 = observer(DialogInput);\nvar _c, _c2;\n$RefreshReg$(_c, \"DialogInput\");\n$RefreshReg$(_c2, \"%default%\");","map":{"version":3,"names":["React","DialogInput","DialogInputComponent","Context","observer","data","init","getEmojiDataFromNative","chat","store","useContext","value","setValue","useState","textField","setTextField","emojiPickerVisible","setEmojiPickerVisible","flagForStyle","setFlagForStyle","cursorPosition","setCursorPosition","pickerRef","useRef","textAreaRef","maxSizeMessage","emojiRE","useEffect","current","focus","length","handleClick","e","contains","target","document","addEventListener","removeEventListener","selectionEnd","toggleEmojiPicker","addEmoji","identifier","ref","start","substring","selectionStart","end","uploadDocumentHandler","useCallback","collectionFiles","files","forEach","item","file","push","handleSendMessage","resultTextValue","replace","match","then","res","console","log","shortcodes"],"sources":["/data/messenger.client/src/containers/DialogInput.tsx"],"sourcesContent":["import React from \"react\";\nimport {DialogInputContainerProps} from \"../models/props/DialogInputContainerProps\";\nimport {DialogInput as DialogInputComponent} from \"../components\";\nimport {Context} from \"../index\";\nimport {observer} from \"mobx-react-lite\";\n\nimport data from '@emoji-mart/data'\nimport { init, getEmojiDataFromNative } from 'emoji-mart'\n\ninit({ data })\n\nconst DialogInput: React.FC<DialogInputContainerProps> = ({chat}) => {\n    const {store} = React.useContext(Context);\n    const [value, setValue] = React.useState<boolean>(false);\n    const [textField, setTextField] = React.useState<string>('');\n    const [emojiPickerVisible, setEmojiPickerVisible] = React.useState<boolean>(false);\n    const [flagForStyle, setFlagForStyle] = React.useState<boolean>(false);\n    const [cursorPosition, setCursorPosition] = React.useState<number>(0);\n\n    const pickerRef = React.useRef<null | HTMLDivElement>(null);\n    const textAreaRef = React.useRef<null | HTMLTextAreaElement>(null);\n\n    const maxSizeMessage: number = 500;\n    const emojiRE = /(\\p{Emoji_Presentation}|\\p{Extended_Pictographic})/gu;\n\n    React.useEffect(() => {\n        textAreaRef.current?.focus();\n\n        if (textField.length > maxSizeMessage * 0.05) {\n            setFlagForStyle(true);\n        } else {\n            setFlagForStyle(false);\n        }\n        if (textField.length > 0) {\n            setValue(true);\n        } else {\n            setValue(false);\n        }\n    }, [textField]);\n\n    React.useEffect(() => {\n        if (emojiPickerVisible) {\n            const handleClick = (e: any) => {\n                if (!pickerRef.current) return;\n                if (!pickerRef.current?.contains(e.target)) {\n                    textAreaRef.current?.focus();\n                    setEmojiPickerVisible(false);\n                }\n            }\n\n            document.addEventListener('click', handleClick);\n\n            return () => {\n                document.removeEventListener('click', handleClick)\n            }\n        }\n    }, [emojiPickerVisible]);\n\n    React.useEffect(() => {\n        if (textAreaRef.current?.selectionEnd!) {\n            textAreaRef.current.selectionEnd = cursorPosition;\n        }\n    }, [cursorPosition]);\n\n    React.useEffect(() => {\n        setTextField('');\n        setCursorPosition(0);\n    }, [chat]);\n\n    const toggleEmojiPicker = () => {\n        textAreaRef.current?.focus();\n        setEmojiPickerVisible(!emojiPickerVisible);\n    }\n\n    const addEmoji = (identifier: string) => {\n        const ref = textAreaRef.current;\n        ref?.focus();\n\n        const start: string = textField.substring(0, ref?.selectionStart);\n        const end: string = textField.substring(ref?.selectionStart || 500);\n\n        setTextField(start + identifier + end);\n        setCursorPosition(start.length + identifier.length);\n    }\n\n    const uploadDocumentHandler = React.useCallback( (e: React.ChangeEvent<HTMLInputElement>) => {\n        let collectionFiles: File[] = [];\n        if (e.target.files) {\n            [...e.target.files].forEach((item) => {\n                const file: File = item;\n                collectionFiles.push(file);\n            });\n        }\n        e.target.value = '';\n    }, [store]);\n\n    const handleSendMessage = (e: React.ChangeEvent<HTMLInputElement>) => {\n        if (textField.length - 1 <= maxSizeMessage) {\n            const resultTextValue = textField.replace(emojiRE, (match) => {\n                getEmojiDataFromNative(match).then(res => {\n                    console.log(res.shortcodes);\n                });\n                return match;\n            });\n            console.log(resultTextValue);\n            setTextField('');\n        }\n    }\n\n    return (\n        <DialogInputComponent\n            toggleEmojiPicker={toggleEmojiPicker}\n            emojiPickerVisible={emojiPickerVisible}\n            setEmojiPickerVisible={setEmojiPickerVisible}\n            value={value}\n            textField={textField}\n            setTextField={setTextField}\n            maxSizeMessage={maxSizeMessage}\n            uploadDocumentHandler={uploadDocumentHandler}\n            handleSendMessage={handleSendMessage}\n            pickerRef={pickerRef}\n            addEmoji={addEmoji}\n            flagForStyle={flagForStyle}\n            textAreaRef={textAreaRef}\n        />\n    );\n}\n\nexport default observer(DialogInput);"],"mappings":";;AAAA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAAQC,WAAW,IAAIC,oBAAoB,QAAO,eAAe;AACjE,SAAQC,OAAO,QAAO,UAAU;AAChC,SAAQC,QAAQ,QAAO,iBAAiB;AAExC,OAAOC,IAAI,MAAM,kBAAkB;AACnC,SAASC,IAAI,EAAEC,sBAAsB,QAAQ,YAAY;AAAA;AAEzDD,IAAI,CAAC;EAAED;AAAK,CAAC,CAAC;AAEd,MAAMJ,WAAgD,GAAG,QAAY;EAAA;EAAA,IAAX;IAACO;EAAI,CAAC;EAC5D,MAAM;IAACC;EAAK,CAAC,GAAGT,KAAK,CAACU,UAAU,CAACP,OAAO,CAAC;EACzC,MAAM,CAACQ,KAAK,EAAEC,QAAQ,CAAC,GAAGZ,KAAK,CAACa,QAAQ,CAAU,KAAK,CAAC;EACxD,MAAM,CAACC,SAAS,EAAEC,YAAY,CAAC,GAAGf,KAAK,CAACa,QAAQ,CAAS,EAAE,CAAC;EAC5D,MAAM,CAACG,kBAAkB,EAAEC,qBAAqB,CAAC,GAAGjB,KAAK,CAACa,QAAQ,CAAU,KAAK,CAAC;EAClF,MAAM,CAACK,YAAY,EAAEC,eAAe,CAAC,GAAGnB,KAAK,CAACa,QAAQ,CAAU,KAAK,CAAC;EACtE,MAAM,CAACO,cAAc,EAAEC,iBAAiB,CAAC,GAAGrB,KAAK,CAACa,QAAQ,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